# -*- coding: utf-8 -*-
from bottle import *
import os


@route("/")
def main():
	return template("index")

@route('/jquery')
def main():
	return template('jquery')

@route('/static/<filename>')
def static(filename):
	return static_file(filename, root = os.path.dirname(os.path.dirname(__file__)))

@post('/calculate')
def calculate():
	def calc():
		print unicode(request.forms.get('operation'))
		if (request.forms.get('operation') == '+'):
			return str(float(request.forms.get('a')) + float(request.forms.get('b')))
		elif (request.forms.get('operation') == '-'):
			return str(float(request.forms.get('a')) - float(request.forms.get('b')))
		elif (request.forms.get('operation') == '*'):
			return str(float(request.forms.get('a')) * float(request.forms.get('b')))
		elif (request.forms.get('operation') == '/'):
			return str(float(request.forms.get('a')) / float(request.forms.get('b'))) if float(request.forms.get('b')) != 0 else u'На нуль не ділиться'

	print unicode(calc())
	return unicode(calc())

run(port = '9091')